/*
 * @Description: 
 * @Autor: kaikaima
 * @Date: 2021-05-17 13:38:28
 * @LastEditors: kaikaima
 * @LastEditTime: 2021-05-25 19:51:37
 */

#include<iostream>
#include<cmath>
#include<iomanip>
#include "Iteration.h"

int main( int argc, char* argv[]){
    double a,epsilon;
    unsigned n;
    std::cin>>epsilon>>a>>n;
    double* A[n-1];
    for(int i=0;i<n-1;i++){
        A[i]=new double [n-1];
        for(int j=0;j<n-1;j++){
            if(i==j) A[i][j]=-(2*epsilon+1.0/n);
            else if(j-i==1) A[i][j]=epsilon+1.0/n;
            else if(i-j==1) A[i][j]=epsilon;
            else A[i][j]=0;
        }
    }
    double* B=new double[n-1];
    for(int i=0;i<n-1;i++){
        if(i==n-2) B[i]=a/(n*n)-epsilon-1.0/n;
        else B[i]=a/(n*n);
    }

    SOR test1(n-1);
    test1.set(A);
    test1.set(B);
    test1.set(0.00001);
    G_S test2(n-1);
    test2.set(A);
    test2.set(B);
    test2.set(0.00001);
    Jacobi test3(n-1);
    test3.set(A);
    test3.set(B);
    test3.set(0.00001);

    std::cout<<"SOR:"<<std::endl;
    double* key=test1.iteration();
    if(key!=NULL)
    for(int i=0;i<n-1;i++){
        std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(4)<<key[i]<<" ";
    }
    std::cout<<std::endl;

    std::cout<<"G_S:"<<std::endl;
    key=test2.iteration();
    if(key!=NULL)
    for(int i=0;i<n-1;i++){
        std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(4)<<key[i]<<" ";
    }
    std::cout<<std::endl;

    std::cout<<"Jacobi:"<<std::endl;
    key=test3.iteration();
    if(key!=NULL)
    for(int i=0;i<n-1;i++){
        std::cout<<std::setiosflags(std::ios::fixed)<<std::setprecision(4)<<key[i]<<" ";
    }
    std::cout<<std::endl;

    for(int i=0;i<n-1;i++) delete[] A[i];
    delete[] B;
    
    return 0;
}